﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using fmtx.Framework.NoSqlHelper;
using MongoDB.Bson;
using MongoDB.Driver;
using System.Threading;
using System.Configuration;
using MongoDB.Driver.Builders;

namespace OnlineDown
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            SetDownOnline();
        }

        private void SetDownOnline()
        {
            System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(DoClearSession));
            timer.Change(1, 1000 * 60 * 30);
        }

        public void DoClearSession(object state)
        {
            try
            {
                MongoOperation<CurrUserM> db = new MongoOperation<CurrUserM>();
                db.MongoCollection.Remove(Query.LT("AddTime", DateTime.Now.AddMinutes(-30)));
            }
            catch (Exception ex)
            {
                
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.notifyIcon1.Visible = false;
            this.Close();
            this.Dispose();
            Application.Exit();
        }

    }
}
